//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.goldhuman.Common.Security;

import com.goldhuman.Common.Octets;

public final class ARCFourSecurity extends Security {
    private byte[] perm = new byte[256];
    private byte index1;
    private byte index2;

    protected ARCFourSecurity() {
    }

    public Object clone() {
        try {
            ARCFourSecurity o = (ARCFourSecurity)super.clone();
            o.perm = new byte[256];
            System.arraycopy(this.perm, 0, o.perm, 0, 256);
            return o;
        } catch (Exception var2) {
            return null;
        }
    }

    public void SetParameter(Octets o) {
        int keylen = o.size();
        byte j = 0;

        int i;
        for(i = 0; i < 256; ++i) {
            this.perm[i] = (byte)i;
        }

        for(i = 0; i < 256; ++i) {
            j = (byte)(j + this.perm[i] + o.getByte(i % keylen));
            byte k = this.perm[i];
            this.perm[i] = this.perm[j & 255];
            this.perm[j & 255] = k;
        }

        this.index1 = this.index2 = 0;
    }

    public Octets Update(Octets o) {
        int len = o.size();

        for(int i = 0; i < len; ++i) {
            this.index2 += this.perm[++this.index1 & 255];
            byte k = this.perm[this.index1 & 255];
            this.perm[this.index1 & 255] = this.perm[this.index2 & 255];
            this.perm[this.index2 & 255] = k;
            byte j = (byte)(this.perm[this.index1 & 255] + this.perm[this.index2 & 255]);
            o.setByte(i, (byte)(o.getByte(i) ^ this.perm[j & 255]));
        }

        return o;
    }
}
